use pest::Position as PestPosition;
use pest::Span as PestSpan;

#[derive(Debug, Clone)]
pub struct Position {
    pub line: usize,
    // TODO: remove dead code
    #[allow(dead_code)]
    pub col: usize,
}

impl From<(usize, usize)> for Position {
    fn from(value: (usize, usize)) -> Self {
        Self {
            line: value.0,
            col: value.1,
        }
    }
}

impl From<&PestPosition<'_>> for Position {
    fn from(value: &PestPosition) -> Self {
        Self {
            line: value.line_col().0,
            col: value.line_col().1,
        }
    }
}

impl From<PestPosition<'_>> for Position {
    fn from(value: PestPosition) -> Self {
        Self {
            line: value.line_col().0,
            col: value.line_col().1,
        }
    }
}

#[allow(dead_code)]
pub struct Span {
    pub start: Position,
    pub end: Position,
}

impl From<(Position, Position)> for Span {
    fn from(value: (Position, Position)) -> Self {
        Self {
            start: value.0,
            end: value.1,
        }
    }
}

impl From<&PestSpan<'_>> for Span {
    fn from(value: &PestSpan) -> Self {
        Self {
            start: value.start_pos().into(),
            end: value.end_pos().into(),
        }
    }
}

impl From<PestSpan<'_>> for Span {
    fn from(value: PestSpan) -> Self {
        Self {
            start: value.start_pos().into(),
            end: value.end_pos().into(),
        }
    }
}
